﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>工艺路线列表</title>
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-from">

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix">
                        工艺路线编号
                    </div>
                    <div>
                        <input id="RouteNo" type="text" placeholder="请输入工艺路线编号" class="layui-input">
                    </div>

                    <div class="layui-input-prefix" style="left:50px">
                        工艺路线名称
                    </div>
                    <div style="left:50px">
                        <input id="RouteName" type="text" placeholder="请输入工艺路线名称" class="layui-input">
                    </div>

                    <div class="layui-input-prefix" style="left:100px">
                        是否启用
                    </div>
                    <div style="width: 100px;left: 100px;">
                        <select id="IsNo" lay-filter="testSelect">
                            <option value="-1">是否启用</option>
                            <option value="1">启用</option>
                            <option value="0">禁用</option>
                        </select>
                    </div>
                </div>
            </div>

            <div style="left:150px">
                <button onclick="Show()" id="searchBtn" type="button" class="layui-btn layui-btn-normal">搜索</button>
            </div>
            <div style="left:170px">
                        <button onclick="Break()" type="button" class="layui-btn layui-btn-primary">重置</button>
                    </div>
            
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div>
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue" lay-on="test-page-custom">
                            <i class="layui-icon layui-icon-add-1">新增</i>   
                        </button>
                    </div>
                </div>
            </div>
            <table style=" left:320px" class="layui-table">
                <thead>
                    <tr>
                        <td><input type="checkbox" id="quanxuan" onclick=" xuanze()" /></td>
                        <td>工艺路线编号</td>
                        <td>工艺路线名称</td>
                        <td>工艺路线说明</td>
                        <td>是否启用</td>
                        <td>备注</td>
                        <td>操作</td>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
            <div id="demo-laypage-all"></div>
        </div>
    </form>
<script>
    layui.use(function () {
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;
        // 事件
        util.on('lay-on', {
            'test-page-custom': function () {
                layer.open({
                    type: 1,
                    area: '100%',
                    resize: false,
                    shadeClose: true,
                    title: '工艺路线新增',
                    content: `
                    <form class="layui-form" action="">
                        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                        <div class="demo-login-container">
                            <div class="layui-form-item">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix" style="left:28px">
                                        编号
                                    </div>
                                    <div style="left:28px">
                                        <input type="text" name="RouteNo" value="" lay-verify="required" placeholder="请输入编号" lay-reqtext="请填写编号" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-prefix" style="left:40px">
                                        名称
                                    </div>
                                    <div style="left:40px">
                                                <input type="text" name="RouteName" value="" lay-verify="required" placeholder="请输入名称" lay-reqtext="请填写名称" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                    <div class="layui-input-prefix" style="left:50px">
                                        是否启用
                                    </div>
                                    <div style="width:300px;left:50px">
                                                <input type="radio" name="IsNo" value="1" title="是" lay-filter="demo-radio-filter" checked>
                                                <input type="radio" name="IsNo" value="0" lay-filter="demo-radio-filter" title="否">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix" style="left:28px">
                                        说明
                                    </div>
                                    <div style="left:28px">
                                                        <textarea style="width:700px" type="textarea" name="RouteExplain" value="" lay-verify="required" placeholder="请输入内容" lay-reqtext="请填写说明" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix" style="left:28px">
                                        备注
                                    </div>
                                    <div style="left:28px">
                                                <textarea style="width:700px" type="textarea" name="Comment" value="" lay-verify="required" placeholder="请输入内容" lay-reqtext="请填写备注" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item" style="width: 100px;left:700px">
                                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login">添加</button>
                            </div>
                        </div>
                        </div>
                    </form>
                    `,
                    success: function () {
                        // 对弹层中的表单进行初始化渲染
                        form.render();
                        // 表单提交事件
                        form.on('submit(demo-login)', function (data) {
                            var field = data.field; // 获取表单字段值
                            let first = {
                                routeNo: $("[name='RouteNo']").val(),
                                routeName: $("[name='RouteName']").val(),
                                isNo: $("[name='IsNo']").val(),
                                routeExplain: $("[name='RouteExplain']").val(),
                                comment: $("[name='Comment']").val()
                            };
                            // 显示填写结果，仅作演示用
                            layer.alert(JSON.stringify(field), {
                                title: '当前填写的字段值'
                            });
                            // 此处可执行 Ajax 等操作
                            // …
                            $.ajax({
                                url: '@ViewBag.FoundationWrite' + "/api/Jocker/Handle",
                                data: JSON.stringify(first),
                                type: 'post',
                                async: true,
                                dataType: 'json',
                                contentType: 'application/json',
                                success:res=>{
                                    if(res>0){
                                        layer.msg('新增成功');
                                        console.log("新增成功");
                                            
                                    }else{
                                        layer.msg('新增失败');
                                        console.log("新增失败");          
                                    }
                                }
                            })


                            return false; // 阻止默认 form 跳转
                        });
                    }
                });
            }
        })
    });
</script>
</body>
</html>
<script>
    layui.use(['util', 'laydate', 'form'], function () {
        var form = layui.form;
        var laypage = layui.laypage;
        var layer = layui.layer;
        var $ = layui.$;
        var laydate = layui.laydate;
        var util = layui.util;

        var pageIndex = 1;
        var pageSize = 2;
        $(function () {
            Show(pageIndex, pageSize);
        });
       $('#searchBtn').click(function () {
            var aaa = $('#RouteNo').val();
            Show(pageIndex, pageSize);
       });
        $('#searchBtn').click(function () {
           var bbb=$('#RouteName').val();
            Show(pageIndex, pageSize);
       });
       form.on('select(testSelect)',function(data){
           showPermission(data.value);
       });
       function Show(index,size){
        var routeNo = $('#RouteNo').val() || "";
       var routeName=$('#RouteName').val()||"";
        var isNo = $('#IsNo').val() || -1;
        $.ajax({
        url: '@ViewBag.FoundationWrite' + '/api/Jocker/CraftRouteList',
        data: JSON.stringify({ routeNo: routeNo, routeName: routeName, isNo: isNo, pageIndex: index, pageSize: size }),
        type: 'post',
        async: false,
        dataType: 'json',
        contentType: 'application/json',
        success: function (res) {
        var tbody = $("tbody");
        tbody.empty();
        console.log(res.data);
            $.each(res.data,function(){
                tbody.append(`<tr>
                <td><input type="checkbox" name="fanxuan" onclick="fan()" /></td>
                <td>${this.routeNo}</td>
                <td>${this.routeName}</td>
                <td>${this.routeExplain}</td>
                <td>${this.isNo === 1 ? '启用' : '禁用'}</td>
                <td>${this.comment}</td>
                <td>
                <a  onclick="EditSupplier('${this.routeId}')">编辑</a>
                </td>
                </tr>`);
            });
            form.render();
            // 完整显示
            laypage.render({
                elem: 'demo-laypage-all', // 元素 id
                count: res.totalCount, // 数据总数
                limit: size, // 每页显示的条数
                curr: index, // 当前页
                limits: [2, 3, 4],
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                jump: function (obj, first) {
                    // 首次不执行
                    // 首次不执行
                    if (!first) {
                        Show(obj.curr, obj.limit);
                    }


                }
            });
           }
       });
       }
    });
    function Break() {};
    function xuanze() {
        $(".fanxuan").prop("checked", $("#quanxuan").prop("checked"));
    }
    function fan() {
        var a = $(".fanxuan").length;
        var a1 = $(".fanxuan:checked").length;
        if (a == a1) {
            $("#quanxuan").prop("checked", true);
        } else {
            $("#quanxuan").prop("checked", false);
        }
    }
    function EditSupplier(routeId) {
     
        location.href = "/Enterprise/CraftRouteUpdate?routeId="+routeId;
    }
</script>
